CC=gcc
CXX=g++
CFLAGS=-Wall $(DEBUG) $(DEFINITIONS) $(CINCLUDES) $(CMISCFLAGS)
CPPFLAGS=-Wall $(DEBUG) $(CPPINCLUDES) $(DEFINITIONS) $(CPPMISCFLAGS)
DEBUG=-O3 -g3
CMISCFLAGS=
CPPMISCFLAGS=

DEFINITIONS=-DLINUX_OS

CINCLUDES=-I. -I$(GDIR)/include/GIMnetAP -I$(GDIR)/utils -I$(GDIR)/include
CPPINCLUDES=-I. -I$(GDIR)/include/GIMnetAP -I$(GDIR)/utils -I$(GDIR)/include \
  `xml2-config --cflags` -I$(GDIR)/GIMI -I$(GDIR)/GIMI/datatypes \
  `ode-config --cflags` \
  -I$(GDIR)/JPEGEncoder \
  -I$(GDIR)/grid  $(MACI_INCLUDE_PATHS) \
  -I$(GDIR)/SVGMapParser/Motti \
  -I$(GDIR)/LnMlib/src/lnmdefs \
  -I$(GDIR)/ImageUtils/AC3DtoGL \
  -I$(GDIR)/ImageUtils/OpenGLTextureLoader \
  $(MACI_EXT_INCLUDE_PATHS)

LD=g++
LDFLAGS=
LIBS=-lrt -lpthread `xml2-config --libs` -lGL -lGLU -lglut `ode-config --libs` -ljpeg\
     $(MACI_INTERFACE_IMAGE_EXT_LIBS) \
     $(MACI_INTERFACE_MAP_EXT_LIBS) \
		 $(LIBSGIMI)
LIBS_NOMAP=-lrt -lpthread `xml2-config --libs` -lGL -lglut `ode-config --libs` $(LIBSGIMI)
GDIR=..
SRCSC=$(MACI_INTERFACE_IMAGE_EXT_C)
SRCSCPP=glutMain.cpp drawutils.cpp J2B2.cpp SandSim/Sand.cpp						\
  Marekbot.cpp LaserScanner.cpp mathutils.cpp MLMA.cpp Object.cpp				\
  Primitive.cpp RayCluster.cpp Shapes.cpp Terrain.cpp Wall.cpp					\
  World.cpp Camera.cpp Sick.cpp URG.cpp Sonar.cpp SonarSet.cpp					\
  $(GDIR)/grid/CGLHeightMap.cpp Protocol.cpp TestObject.cpp							\
  LandMine.cpp SimCtrlObject.cpp MottiPbV.cpp Car.cpp Obstacle.cpp			\
  Obstacle2.cpp Avant.cpp Gavant.cpp Skywalker.cpp AGV.cpp Ceilbot.cpp	\
  $(GDIR)/ImageUtils/AC3DtoGL/AC3DtoGL.cpp \
  $(GDIR)/ImageUtils/OpenGLTextureLoader/OpenGLTextureLoader.cpp \
	A635Sensors.cpp

SRCSCPP+=$(sort $(MACI_BASE_SRC_CPP) $(MACI_EXT_SRC_CPP)								\
	 $(MACI_INTERFACE_RANGING_COMMON_CPP)																	\
	 $(MACI_INTERFACE_RANGINGSERVER_CPP)																	\
	 $(MACI_INTERFACE_SPEEDCTRL_COMMON_CPP)																\
	 $(MACI_INTERFACE_SPEEDCTRLSERVER_CPP)																\
	 $(MACI_INTERFACE_POSITION_COMMON_CPP)																\
	 $(MACI_INTERFACE_POSITIONSERVER_CPP)																	\
	 $(MACI_INTERFACE_JOINTGROUPCTRL_COMMON_CPP)													\
	 $(MACI_INTERFACE_JOINTGROUPCTRLSERVER_CPP)														\
	 $(MACI_INTERFACE_MAP_COMMON_CPP) $(MACI_INTERFACE_IMAGE_COMMON_CPP)	\
	 $(MACI_INTERFACE_IMAGESERVER_CPP)																		\
	 $(MACI_INTERFACE_ENERGY_COMMON_CPP)																	\
	 $(MACI_INTERFACE_ENERGYSERVER_CPP)																		\
	 $(MACI_INTERFACE_COORDINATEDRIVESERVER_CPP)													\
	 $(MACI_INTERFACE_COORDINATEDRIVE_COMMON_CPP)													\
	 $(MACI_INTERFACE_UNITSERVER_CPP) $(MACI_INTERFACE_UNIT_COMMON_CPP)		\
	 $(MACI_INTERFACE_MAPSERVER_CPP) $(MACI_INTERFACE_MAPCLIENT_CPP)			\
	 $(MACI_INTERFACE_MAP_EXT_CPP) $(MACI_INTERFACE_IMAGE_EXT_CPP) )


VPATH=
CPPGIMI=
CGIMI=

## Build GIMI and it's dependencies.
## Files are set to CGIMI and CPPGIMI variables
include $(GDIR)/GIMI/Makefile.gimi
MACIPATH=$(GDIR)/MaCI
include $(GDIR)/MaCI/interfaces/MaCI-interfaces.Makefile


## Construct final lists of CPP and C objects
OBJSC=$(CGIMI:.c=.o) $(SRCSC:.c=.o)
OBJSCPP=$(CPPGIMI:.cpp=.opp) $(SRCSCPP:.cpp=.opp)

## Define compiles and links
COMPILEC=$(CC) $(CFLAGS) $(CINCLUDES) -c
COMPILECPP=$(CXX) $(CPPFLAGS) $(CPPINCLUDES) -c
LINK=$(LD) $(LDFLAGS)

.PHONY: all clean

all: FSRSim

FSRSim-glut: FSRSim

FSRSim: $(OBJSC) $(OBJSCPP)
	@$(LINK) -o FSRSim $(OBJSC) $(OBJSCPP) $(LIBS)
	@echo "      [LD] $@"

FSRSim-motti: $(OBJSC) $(OBJSCPP) $(GDIR)/SVGMapParser/Motti/MottiMap.opp
	@rm AGV.opp MottiPbV.opp
	@$(COMPILECPP) -DMOTTI_MAP_DECODER_SUPPORT -o AGV.opp AGV.cpp
	@$(COMPILECPP) -DMOTTI_MAP_DECODER_SUPPORT -o MottiPbV.opp MottiPbV.cpp
	@$(LINK) -o FSRSim $(OBJSC) $(OBJSCPP) $(GDIR)/SVGMapParser/Motti/MottiMap.opp \
	$(LIBS)
	@echo "      [LD] $@"

clean:
	rm -f $(OBJSC) $(OBJSCPP) *.out *~ *.d *.dpp FSRSim

## Below this is dependency generation stuff, no need to change.
## Compile rule for all .o (.c) file
%.o:    %.c
	@$(COMPILEC) -o $@ $<
	@echo "      [CC] $<"

## Compile rule for all .opp (.cpp) files
%.opp:  %.cpp
	@$(COMPILECPP) -o $@ $<
	@echo "      [CXX] $<"

